package br.com.pangalacteos.apresentacao;

import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;

public class FrmPrincipal extends javax.swing.JFrame {

    static FrmPrincipal frmPrincipal = getInstance();
    
    public static FrmPrincipal getInstance(){
        if (frmPrincipal != null){
            return frmPrincipal;
        }
        return new FrmPrincipal();
    }
    
    private FrmPrincipal() {
        initComponents();
        this.setSize(810, 648);

        for (Component comp : pnEsquerdo.getComponents()) {
            if (comp instanceof JScrollPane) {
                for(Component lista : ((JScrollPane)comp).getComponents()){
                    lista.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblBarraStatus = new javax.swing.JLabel();
        pnPrincipal = new javax.swing.JPanel();
        tbBarraFerramentas = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        spPrincipal = new javax.swing.JSplitPane();
        pnEsquerdo = new javax.swing.JPanel();
        lblCadastrar = new javax.swing.JLabel();
        scpCadastrar = new javax.swing.JScrollPane();
        lstCadastrar = new javax.swing.JList();
        lblConsultar = new javax.swing.JLabel();
        scpConsultar = new javax.swing.JScrollPane();
        lstConsultar = new javax.swing.JList();
        scpTemas = new javax.swing.JScrollPane();
        lstRelatorios = new javax.swing.JList();
        lblRelatorios = new javax.swing.JLabel();
        lblGeral = new javax.swing.JLabel();
        scpGeral = new javax.swing.JScrollPane();
        lstGeral = new javax.swing.JList();
        lblCadastrar1 = new javax.swing.JLabel();
        scpNovo = new javax.swing.JScrollPane();
        lstInicio = new javax.swing.JList();
        tpJanelas = new javax.swing.JTabbedPane();
        pnSistema = new javax.swing.JPanel();
        pnJanelas = new javax.swing.JDesktopPane();
        mnBarraPrincipal = new javax.swing.JMenuBar();
        mnInicio = new javax.swing.JMenu();
        mnExecutarPagamento = new javax.swing.JMenuItem();
        mnSeparadorInicio = new javax.swing.JSeparator();
        mnSair = new javax.swing.JMenuItem();
        mnCadastrar = new javax.swing.JMenu();
        mnCadastrarFatura = new javax.swing.JMenuItem();
        mnCadastrarFornecedor = new javax.swing.JMenuItem();
        mnConsultar = new javax.swing.JMenu();
        mnConsultarFatura = new javax.swing.JMenuItem();
        mnConsultarFornecedor = new javax.swing.JMenuItem();
        mnTemas = new javax.swing.JMenu();
        mnAjuda = new javax.swing.JMenu();
        mnSobre = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("..:: Pangalácteos Nomades ::.");
        setMinimumSize(new java.awt.Dimension(810, 648));

        lblBarraStatus.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblBarraStatus.setText("Status");
        lblBarraStatus.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblBarraStatus.setPreferredSize(new java.awt.Dimension(41, 25));
        getContentPane().add(lblBarraStatus, java.awt.BorderLayout.PAGE_END);

        pnPrincipal.setLayout(new java.awt.BorderLayout());

        tbBarraFerramentas.setPreferredSize(new java.awt.Dimension(100, 60));

        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setPreferredSize(new java.awt.Dimension(53, 60));
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tbBarraFerramentas.add(jButton1);

        pnPrincipal.add(tbBarraFerramentas, java.awt.BorderLayout.PAGE_START);

        spPrincipal.setDividerLocation(200);
        spPrincipal.setOneTouchExpandable(true);

        lblCadastrar.setBackground(new java.awt.Color(0, 0, 0));
        lblCadastrar.setFont(new java.awt.Font("Dialog", 1, 14));
        lblCadastrar.setForeground(new java.awt.Color(255, 255, 255));
        lblCadastrar.setText(" > Cadastrar");
        lblCadastrar.setOpaque(true);

        scpCadastrar.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scpCadastrar.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        lstCadastrar.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Fatura", "Fornecedor" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstCadastrar.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstCadastrar.setAutoscrolls(false);
        lstCadastrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstCadastrarMouseClicked(evt);
            }
        });
        scpCadastrar.setViewportView(lstCadastrar);

        lblConsultar.setBackground(new java.awt.Color(0, 0, 0));
        lblConsultar.setFont(new java.awt.Font("Dialog", 1, 14));
        lblConsultar.setForeground(new java.awt.Color(255, 255, 255));
        lblConsultar.setText(" > Consultar");
        lblConsultar.setOpaque(true);

        scpConsultar.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scpConsultar.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        lstConsultar.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Fatura", "Fornecedor" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstConsultar.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstConsultar.setAutoscrolls(false);
        lstConsultar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstConsultarMouseClicked(evt);
            }
        });
        scpConsultar.setViewportView(lstConsultar);

        scpTemas.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scpTemas.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        lstRelatorios.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Fatura" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstRelatorios.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstRelatorios.setAutoscrolls(false);
        lstRelatorios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstRelatoriosMouseClicked(evt);
            }
        });
        scpTemas.setViewportView(lstRelatorios);

        lblRelatorios.setBackground(new java.awt.Color(0, 0, 0));
        lblRelatorios.setFont(new java.awt.Font("Dialog", 1, 14));
        lblRelatorios.setForeground(new java.awt.Color(255, 255, 255));
        lblRelatorios.setText(" > Relatórios");
        lblRelatorios.setOpaque(true);

        lblGeral.setBackground(new java.awt.Color(0, 0, 0));
        lblGeral.setFont(new java.awt.Font("Dialog", 1, 14));
        lblGeral.setForeground(new java.awt.Color(255, 255, 255));
        lblGeral.setText(" > Geral");
        lblGeral.setOpaque(true);

        scpGeral.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scpGeral.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        lstGeral.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Sobre o Programa", "Sair" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstGeral.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstGeral.setAutoscrolls(false);
        lstGeral.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstGeralMouseClicked(evt);
            }
        });
        scpGeral.setViewportView(lstGeral);

        lblCadastrar1.setBackground(new java.awt.Color(0, 0, 0));
        lblCadastrar1.setFont(new java.awt.Font("Dialog", 1, 14));
        lblCadastrar1.setForeground(new java.awt.Color(255, 255, 255));
        lblCadastrar1.setText(" > Início");
        lblCadastrar1.setOpaque(true);

        scpNovo.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scpNovo.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        lstInicio.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Executar pagamento" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstInicio.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstInicio.setAutoscrolls(false);
        lstInicio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstInicioMouseClicked(evt);
            }
        });
        scpNovo.setViewportView(lstInicio);

        javax.swing.GroupLayout pnEsquerdoLayout = new javax.swing.GroupLayout(pnEsquerdo);
        pnEsquerdo.setLayout(pnEsquerdoLayout);
        pnEsquerdoLayout.setHorizontalGroup(
            pnEsquerdoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblCadastrar1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(scpNovo, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(lblCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(scpCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(lblConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(scpConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(lblRelatorios, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(scpTemas, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(lblGeral, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(scpGeral, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
        );
        pnEsquerdoLayout.setVerticalGroup(
            pnEsquerdoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnEsquerdoLayout.createSequentialGroup()
                .addComponent(lblCadastrar1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblRelatorios, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpTemas, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblGeral, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpGeral, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        spPrincipal.setLeftComponent(pnEsquerdo);

        pnSistema.setLayout(new java.awt.CardLayout());
        pnSistema.add(pnJanelas, "card2");

        tpJanelas.addTab("Bem vindo", pnSistema);

        spPrincipal.setRightComponent(tpJanelas);
        tpJanelas.getAccessibleContext().setAccessibleName("Bem vindo");

        pnPrincipal.add(spPrincipal, java.awt.BorderLayout.CENTER);

        getContentPane().add(pnPrincipal, java.awt.BorderLayout.CENTER);

        mnInicio.setText("Início");

        mnExecutarPagamento.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
        mnExecutarPagamento.setText("Executar pagamento");
        mnInicio.add(mnExecutarPagamento);
        mnInicio.add(mnSeparadorInicio);

        mnSair.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        mnSair.setText("Sair");
        mnInicio.add(mnSair);

        mnBarraPrincipal.add(mnInicio);

        mnCadastrar.setText("Cadastrar");

        mnCadastrarFatura.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, java.awt.event.InputEvent.SHIFT_MASK));
        mnCadastrarFatura.setText("Fatura");
        mnCadastrar.add(mnCadastrarFatura);

        mnCadastrarFornecedor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.SHIFT_MASK));
        mnCadastrarFornecedor.setText("Fornecedor");
        mnCadastrar.add(mnCadastrarFornecedor);

        mnBarraPrincipal.add(mnCadastrar);

        mnConsultar.setText("Consultar");

        mnConsultarFatura.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, java.awt.event.InputEvent.CTRL_MASK));
        mnConsultarFatura.setText("Fatura");
        mnConsultar.add(mnConsultarFatura);

        mnConsultarFornecedor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
        mnConsultarFornecedor.setText("Fornecedor");
        mnConsultar.add(mnConsultarFornecedor);

        mnBarraPrincipal.add(mnConsultar);

        mnTemas.setText("Temas");
        mnBarraPrincipal.add(mnTemas);

        mnAjuda.setText("Ajuda");

        mnSobre.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, java.awt.event.InputEvent.SHIFT_MASK));
        mnSobre.setText("Sobre o Programa");
        mnAjuda.add(mnSobre);

        mnBarraPrincipal.add(mnAjuda);

        setJMenuBar(mnBarraPrincipal);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void lstCadastrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstCadastrarMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        try {
            JComponent tab = null;
            String tituloTab = "Aba";
            JPopupMenu contextMenu = new JPopupMenu();
            
            switch (lstCadastrar.getSelectedIndex()) {
                case 0:
                    tab = new FrmFatura();
                    tituloTab = "Cad. Fatura";
                    break;
                case 1:
                    tab = new FrmFornecedor();
                    tituloTab = "Cad. Fornecedor";
                    break;
                default:
                    throw new IllegalStateException("Menu inválido");
            }
            
            contextMenu.add(new JSeparator());
            JMenuItem mnContextFechar = new javax.swing.JMenuItem();
            //TODO: fazer o ctrl f4 funcionar
            mnContextFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
            mnContextFechar.setText("Fechar");
            contextMenu.add(mnContextFechar);
            tab.setComponentPopupMenu(contextMenu);
            tpJanelas.addTab(tituloTab, tab);
            tpJanelas.setSelectedComponent(tab);
            
            mnContextFechar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mnContextFecharActionPerformed(evt);
                }
            });
            
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(tpJanelas, "Ocorreu um erro interno," +
                    " por favor relate este erro ao administrador da rede.\n" +
                    "Exceção: " + ex, "Erro interno",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
    }
}//GEN-LAST:event_lstCadastrarMouseClicked

private void mnContextFecharActionPerformed(java.awt.event.ActionEvent evt) {
        JMenuItem mnContextFechar = (JMenuItem) evt.getSource();
        JPopupMenu contextMenu = (JPopupMenu) mnContextFechar.getParent();
        Component panel = contextMenu.getInvoker();
        fecharAba(panel, false);
}

private void lstInicioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstInicioMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        try {
            JComponent tab = null;
            String tituloTab = "Aba";
            
            switch (lstInicio.getSelectedIndex()) {
                case 0:
                    tab = new FrmPagamento();
                    tituloTab = "Pagamento";
                    break;
                default:
                    throw new IllegalStateException("Menu inválido");
            }
            
            JPopupMenu contextMenu = new JPopupMenu();
            contextMenu.add(new JSeparator());
            JMenuItem mnContextFechar = new javax.swing.JMenuItem();
            //TODO: fazer o ctrl f4 funcionar
            mnContextFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
            mnContextFechar.setText("Fechar");
            contextMenu.add(mnContextFechar);
            tab.setComponentPopupMenu(contextMenu);
            tpJanelas.addTab(tituloTab, tab);
            tpJanelas.setSelectedComponent(tab);
            
            mnContextFechar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mnContextFecharActionPerformed(evt);
                }
            });
            
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(tpJanelas, "Ocorreu um erro interno," +
                    " por favor relate este erro ao administrador da rede.\n" +
                    "Exceção: " + ex, "Erro interno",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
    }
}//GEN-LAST:event_lstInicioMouseClicked

private void lstConsultarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstConsultarMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        try {
            JComponent tab = null;
            String tituloTab = "Aba";
            JPopupMenu contextMenu = new JPopupMenu();
            
            switch (lstConsultar.getSelectedIndex()) {
                case 0:
                    tab = new FrmConsultaFatura();
                    tituloTab = "Con. Fatura";
                    break;
                case 1:
                    tab = new FrmConsultaFornecedor();
                    tituloTab = "Con. Fornecedor";
                    break;
                default:
                    throw new IllegalStateException("Menu inválido");
            }
            
            contextMenu.add(new JSeparator());
            JMenuItem mnContextFechar = new javax.swing.JMenuItem();
            //TODO: fazer o ctrl f4 funcionar
            mnContextFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
            mnContextFechar.setText("Fechar");
            contextMenu.add(mnContextFechar);
            tab.setComponentPopupMenu(contextMenu);
            tpJanelas.addTab(tituloTab, tab);
            tpJanelas.setSelectedComponent(tab);
            
            mnContextFechar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mnContextFecharActionPerformed(evt);
                }
            });
            
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(tpJanelas, "Ocorreu um erro interno," +
                    " por favor relate este erro ao administrador da rede.\n" +
                    "Exceção: " + ex, "Erro interno",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
    }
}//GEN-LAST:event_lstConsultarMouseClicked

private void lstGeralMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstGeralMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        try {
            JComponent tab = null;
            String tituloTab = "Aba";
            
            switch (lstGeral.getSelectedIndex()) {
                case 0:
                    tab = new FrmSobre();
                    tituloTab = "Sobre";
                    break;
                case 1:
                    throw new Exception("Não vai sair não!!!");
                default:
                    throw new IllegalStateException("Menu inválido");
            }
            
            JPopupMenu contextMenu = new JPopupMenu();
            contextMenu.add(new JSeparator());
            JMenuItem mnContextFechar = new javax.swing.JMenuItem();
            //TODO: fazer o ctrl f4 funcionar
            mnContextFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
            mnContextFechar.setText("Fechar");
            contextMenu.add(mnContextFechar);
            tab.setComponentPopupMenu(contextMenu);
            tpJanelas.addTab(tituloTab, tab);
            tpJanelas.setSelectedComponent(tab);
            
            mnContextFechar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mnContextFecharActionPerformed(evt);
                }
            });
            
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(tpJanelas, "Ocorreu um erro interno," +
                    " por favor relate este erro ao administrador da rede.\n" +
                    "Exceção: " + ex, "Erro interno",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
    }
}//GEN-LAST:event_lstGeralMouseClicked

private void lstRelatoriosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstRelatoriosMouseClicked
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        try {
            JComponent tab = null;
            String tituloTab = "Aba";
            
            switch (lstRelatorios.getSelectedIndex()) {
                case 0:
                    tab = new FrmRelatorioFatura();
                    tituloTab = "Rel. Fatura";
                    break;
                case 1:
                    tab = new FrmRelatorioSaldo();
                    tituloTab = "Rel. Saldo";
                    break;
                default:
                    throw new IllegalStateException("Menu inválido");
            }
            
            JPopupMenu contextMenu = new JPopupMenu();
            contextMenu.add(new JSeparator());
            JMenuItem mnContextFechar = new javax.swing.JMenuItem();
            //TODO: fazer o ctrl f4 funcionar
            mnContextFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
            mnContextFechar.setText("Fechar");
            contextMenu.add(mnContextFechar);
            tab.setComponentPopupMenu(contextMenu);
            tpJanelas.addTab(tituloTab, tab);
            tpJanelas.setSelectedComponent(tab);
            
            mnContextFechar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mnContextFecharActionPerformed(evt);
                }
            });
            
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(tpJanelas, "Ocorreu um erro interno," +
                    " por favor relate este erro ao administrador da rede.\n" +
                    "Exceção: " + ex, "Erro interno",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
    }
}//GEN-LAST:event_lstRelatoriosMouseClicked

public static void fecharAba(Component component, boolean force){
    if (force || JOptionPane.showConfirmDialog
            (null, "Tem certeza que deseja fechar esta aba?", "Tem certeza?", 
            JOptionPane.YES_NO_CANCEL_OPTION)
        == JOptionPane.YES_OPTION){
    Container container = component.getParent();
    container.remove(component);
    }
}

public void abreAba(JComponent component, String titulo){
        try {
            JPopupMenu contextMenu = new JPopupMenu();
            contextMenu.add(new JSeparator());
            JMenuItem mnContextFechar = new javax.swing.JMenuItem();
            //TODO: fazer o ctrl f4 funcionar
            mnContextFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.CTRL_MASK));
            mnContextFechar.setText("Fechar");
            contextMenu.add(mnContextFechar);
            component.setComponentPopupMenu(contextMenu);
            tpJanelas.addTab(titulo, component);
            tpJanelas.setSelectedComponent(component);
            
            mnContextFechar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    mnContextFecharActionPerformed(evt);
                }
            });
            
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(tpJanelas, "Ocorreu um erro interno," +
                    " por favor relate este erro ao administrador da rede.\n" +
                    "Exceção: " + ex, "Erro interno",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
}


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblBarraStatus;
    private javax.swing.JLabel lblCadastrar;
    private javax.swing.JLabel lblCadastrar1;
    private javax.swing.JLabel lblConsultar;
    private javax.swing.JLabel lblGeral;
    private javax.swing.JLabel lblRelatorios;
    private javax.swing.JList lstCadastrar;
    private javax.swing.JList lstConsultar;
    private javax.swing.JList lstGeral;
    private javax.swing.JList lstInicio;
    private javax.swing.JList lstRelatorios;
    private javax.swing.JMenu mnAjuda;
    private javax.swing.JMenuBar mnBarraPrincipal;
    private javax.swing.JMenu mnCadastrar;
    private javax.swing.JMenuItem mnCadastrarFatura;
    private javax.swing.JMenuItem mnCadastrarFornecedor;
    private javax.swing.JMenu mnConsultar;
    private javax.swing.JMenuItem mnConsultarFatura;
    private javax.swing.JMenuItem mnConsultarFornecedor;
    private javax.swing.JMenuItem mnExecutarPagamento;
    private javax.swing.JMenu mnInicio;
    private javax.swing.JMenuItem mnSair;
    private javax.swing.JSeparator mnSeparadorInicio;
    private javax.swing.JMenuItem mnSobre;
    private javax.swing.JMenu mnTemas;
    private javax.swing.JPanel pnEsquerdo;
    private javax.swing.JDesktopPane pnJanelas;
    private javax.swing.JPanel pnPrincipal;
    private javax.swing.JPanel pnSistema;
    private javax.swing.JScrollPane scpCadastrar;
    private javax.swing.JScrollPane scpConsultar;
    private javax.swing.JScrollPane scpGeral;
    private javax.swing.JScrollPane scpNovo;
    private javax.swing.JScrollPane scpTemas;
    private javax.swing.JSplitPane spPrincipal;
    private javax.swing.JToolBar tbBarraFerramentas;
    private javax.swing.JTabbedPane tpJanelas;
    // End of variables declaration//GEN-END:variables
}
